# _*_coding:utf-8 _*_
# @Time    :2022/3/18 9:02
# @Author  :gxp
# @FileName: calculate.py
# @Software: PyCharm

import random

sign = ['+', '-', '*', '/']

# 生成随机数


def randomNum():
    sign_index = random.randint(0, 3)
    sign_index2 = random.randint(0, 3)
    num1 = random.randint(0, 100)
    num2 = random.randint(1, 100)
    num3 = random.randint(1, 100)
    return sign_index, sign_index2, num1, num2, num3

# 计算


def calculate():
    # 计数
    calculate_num = 0
    while True:
        sign_index, sign_index2, num1, num2, num3 = randomNum()
        str1 = str(num1) + sign[sign_index] + \
            str(num2) + sign[sign_index2] + str(num3)
        result = eval(str1)
        # 判断是否为整数
        if isinstance(result, int):
            if result >= 0 and result <= 100:
                print(str1 + " = ? ")
                calculate_num += 1
                answer = input("输入您的结果：")
                if str(answer) == str(result):
                    print("congratulations!")
                else:
                    print("you are wrong!")
        if calculate_num >= 10:
            break


if __name__ == '__main__':
    calculate()
